package com.zfjt.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.NewsBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.packnum.PackNum00034;
import com.zfjt.service.NewsBeanService;

/**
 * 点击新闻详情
 * @author xk
 * @version 1.0
 * @date 2017年4月16日
 */
@Controller
public class NewsDetailsController {

	//返回对象
	private ReturnBean mReturn;
	
	private Map<String, String> fhdata;
		
	@Autowired
	private NewsBeanService mNews;
	
	@RequestMapping(value="00034")
	@ResponseBody
	public ReturnBean PublishNews(HttpSession hseesion){
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00034 num00034 = JSON.parseObject(data,PackNum00034.class); 	
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {
			mReturn.setPortnum("00032");
			mReturn.setCode("001");
			fhdata.put("error", "TOKEN_ERROR");
			mReturn.setData(JSON.toJSONString(fhdata));
		}else{	
			NewsBean dg = mNews.selectByPrimaryKey(num00034.getId());
			fhdata.put("title", dg.getTitle());
			fhdata.put("addtime", dg.getAddTime());
			fhdata.put("details", dg.getDetails());
			fhdata.put("details", dg.getIssuer());
			mReturn.setPortnum("00034");
			mReturn.setCode("000");		
			mReturn.setData(JSON.toJSONString(fhdata));	
		}
		return mReturn;
	}
}
